package com.itheima.controller;

import com.itheima.common.Paging;
import com.itheima.common.R;
import com.itheima.dto.UserLinkUserDto;
import com.itheima.service.UserLinkUserService;
import com.itheima.vo.userLinkUser.UserLinkUserFindVo;
import com.itheima.vo.userLinkUser.UserLinkUserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <h1>聊天对象控制类</h1>
 *
 * @author <a href="515857087@qq.com">叶世铭</a>
 * @since 2022/11/2
 */
@RestController
@RequestMapping("/userLinkUser")
@Api(tags = "好友api")
public class UserLinkUserController {

    @Resource
    private UserLinkUserService userLinkUserService;

    /**
     * 展示已建立的聊天
     *
     * @param keyword 关键字
     * @return 聊天列表对象vo
     * @throws Exception
     */
    @ApiOperation(value = "展示好友聊天列表")
    @GetMapping("/showChats")
    public R<List<UserLinkUserVo>> showChats(@RequestParam("keyword") String keyword) throws Exception {
        return R.success(userLinkUserService.showChats(keyword));
    }

    /**
     * 查找用户
     *
     * @param userLinkUserDto 筛选聊天好友dto
     * @return 查找好友vo
     * @throws Exception
     */
    @ApiOperation(value = "查找用户")
    @PostMapping("/findUser")
    public R<Paging<UserLinkUserFindVo>> findUser(@RequestBody UserLinkUserDto userLinkUserDto) throws Exception {
        return R.success(userLinkUserService.findUser(userLinkUserDto));
    }

    /**
     * 置顶用户
     *
     * @param userId 用户id
     * @return 结果
     * @throws Exception 异常
     */
    @ApiOperation(value = "置顶用户")
    @PutMapping("/topUser")
    public R<String> topUser(@RequestParam("userId") String userId) throws Exception {
        userLinkUserService.topUser(userId);
        return R.success("置顶成功");
    }

    /**
     * 取消置顶用户
     *
     * @param userId 用户id
     * @return 结果
     * @throws Exception 异常
     */
    @ApiOperation(value = "取消置顶用户")
    @DeleteMapping ("/cancelTopUser")
    public R<String> cancelTopUser(@RequestParam("userId") String userId) throws Exception{
        userLinkUserService.cancelTopUser(userId);
        return R.success("取消置顶成功");
    }
}
